
function loginChk(id,pw,device_id){

    console.log("index.ajax.js >> -------------------- loginChk() ");
    openDb();
    displayloading();
    nowAvatarId = id;
    nowAvatarPw = pw;
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_loginchk.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           //timeout:30000,
           //contentType:"application/json; charset=UTF-8",
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw, "device_id" : device_id} ]}
                               ),
           dataType: "json",
           success: function(data) {
           $(data.login).each(function(key,val){
                              //console.log("index.ajax.js >> "+val.ack);
                              var ack = val.ack;
                              
                              if(ack == "succ"){
                              window.scrollTo(0,0);
                              sessionStorage.setItem("id",id);
                              
                              console.log("index.ajax.js >> initialCCR() ");
                              //initialCCR();  //���耳�������
                              connect_server();//���耳�������
                              console.log("ccrViewer.js >>>>>>>>>>> selectCCR() start ");
                              
                              selectCCR();
                              
                             console.log("ccrViewer.js >>>>>>>>>>> selectCCR() end ");
                              
                              undisplayloading();
                              
                              console.log("index.ajax.js >> mainGo() ");
                              mainGo();
                              
                              
                              
                              
                              }else{
                                alert("ID OR Password Check Please!");
                              }
                              
                              
                              
                              });
           
           },
           error: function(msg) {
           alert(msg.statusText);
           console.log("index.ajax.js >>loginChk error " +msg.statusText);
           }
           });
    
    /*
    $('#modify').attr('value','true');*/
    contractList(id,pw);
    console.log("index.ajax.js >>-----contractList --------------------------------------------------");    
    recommendList(id,pw);
    console.log("index.ajax.js >>-----recommendList --------------------------------------------------");
    settingList(id,pw);
    console.log("index.ajax.js >>-----settingList --------------------------------------------------");
    agentList();
    console.log("index.ajax.js >>-----agentList --------------------------------------------------");
    lifelogList(id,pw);
    console.log("index.ajax.js >>-----lifelogList --------------------------------------------------");
    
    
    
    lifeManagerList(id,pw);
    console.log("index.ajax.js >>-----lifemanager List --------------------------------------------------");

    
    var panelScroll = new iScroll("panelScroll",{hScroll:false});
   // var panelScroll = new IScroll('#panelScroll', { mouseWheel: true });
    
    
   
    
}

function callRed(){

    
    console.log("ccrViewer.js >>>>>>>>>>> AdvanceDirectivesMap.size() " + AdvanceDirectivesMap.size());
    
    ccrViewHiddenRed(AdvanceDirectivesMap.size(),"red01" );
    ccrViewHiddenRed(AlertsMap.size(),"red02" );
}

function eosloginChk(){
    
     displayloading();

    var did = $("#did").attr("value");
    var dpw = $("#dpw").attr("value");
    
     console.log("index.ajax.js >>-----did --------------------------------------------------" + did);
     console.log("index.ajax.js >>-----dpw --------------------------------------------------" + dpw);
    
//escape(encodeURIComponent(id))
    $.ajax({
           type: "POST",
           url:  "http://eos.snubi.org:8080/dialysisnet/healthavatar/loginchk.jsp?id="+escape(encodeURIComponent(did))+"&pw="+dpw,
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           contentType: "application/x-www-form-urlencoded; charset=UTF-8",
          // async: false,
           dataType: "html",
           success: function(data) {
             console.log("index.ajax.js >>eosloginChk succ " +data);
            if(data == "F"){
                alert("濡�洹몄�몄��蹂댁�ㅻ��!");
            }else{
                eosCcrDownload(data);
                console.log("index.ajax.js >>eosCcrDownload file " +data);
            }
           },
           error: function(msg) {
             alert(msg.statusText);
             console.log("index.ajax.js >>eosloginChk error " +msg.statusText);
           }
           });


}





function eosCcrDownload(file){
    //escape(encodeURIComponent(id))
    $.ajax({
           type: "POST",
           url:  "http://eos.snubi.org:8080/dialysisnet/healthavatar/uploadccr/" + file,
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           contentType: "application/x-www-form-urlencoded; charset=UTF-8",
           //async: false,
           dataType: "html",
           success: function(data) {
            readJsonStringCCR(data);
           },
           error: function(msg) {
           alert(msg.statusText);
           console.log("index.ajax.js >>eosCcrDownload error " +msg.statusText);
           }
           });
    
    
}

function readJsonStringCCR(json){
    
    
    
    //openDb();
    console.log("ccrViewer.js >>  initialCCR() readJsonString() ");
    
    
    //40line ������ ��쎌�대�ㅼ�� evt.target.result瑜� lib瑜� ��댁�⑺�� ������
    var jsonStr = xml2json(parseXml(json),"");
    
    console.log("ccrViewer.js >>  initialCCR() xml2json() ");
    
    var obj = jQuery.parseJSON(jsonStr);//�����깅�� ��곗�댄�곕�� ��ㅻ�������몃�� 蹂����
    
    
    console.log("ccrViewer.js >>>>>>>>>>>  bodyFunc.js 13 section insert start");
    
    try{ payer(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Payers']['ccr:Payer'],obj); }catch(err){}
    try{ immunization(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Immunizations']['ccr:Immunization'],obj);}catch(err){}
    try{ ccrresults(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Results']['ccr:Result'],obj); }catch(err){}
    try{ encounters(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Encounters']['ccr:Encounter'],obj); }catch(err){}
    try{ advanceDirect(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:AdvanceDirectives']['ccr:AdvanceDirective'],obj); }catch(err){}
    try{ functionalStat(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:FunctionalStatus']['ccr:Function'],obj); }catch(err){}
    try{ familyHistory(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:FamilyHistory']['ccr:FamilyProblemHistory'],obj); }catch(err){}
    try{ socialHistory(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:SocialHistory']['ccr:SocialHistoryElement'],obj); }catch(err){}
    try{ problems(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Problems']['ccr:Problem'],obj); }catch(err){}
    try{ alerts(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Alerts']['ccr:Alert'],obj); }catch(err){}
    try{ medications(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Medications']['ccr:Medication'],obj); }catch(err){}
    try{ vitalSigns(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:VitalSigns']['ccr:Result'],obj); }catch(err){}
    
    console.log("ccrViewer.js >>>>>>>>>>>  procedure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

    try{ procedure(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Procedures']['ccr:Procedure'],obj); }catch(err){}
    
    console.log("ccrViewer.js >>>>>>>>>>>  procedure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    
    try{ vital = obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:VitalSigns']['ccr:Result']; }catch(err){}
    
    try{ procedure2(obj['ccr:ContinuityOfCareRecord']['ccr:Body']['ccr:Procedures']['ccr:Procedure']['ccr:Question'],obj); }catch(err){}
    
       
    
    
    console.log("ccrViewer.js >>>>>>>>>>> selectCCR() ");
    selectCCR();
    
    
    
    ccrViewHiddenBlue(UpdatePayersMap.size(),"blue01" );
    ccrViewHiddenBlue(UpdateAdvanceDirectivesMap.size(),"blue02" );
    ccrViewHiddenBlue(UpdateAlertsMap.size(),"blue03" );
    
    ccrViewHiddenBlue(UpdateProblemsMap.size() + UpdateFunctionalStatusMap.size(),"blue04" );
    
    ccrViewHiddenBlue(UpdateFamilyHistoryMap.size() + UpdateSocialHistoryMap.size(),"blue05" );
    
    ccrViewHiddenBlue(UpdateResultsMap.size() + UpdateVitalSignsMap.size(),"blue06" );
    
    ccrViewHiddenBlue(UpdateMedicationsMap.size() + UpdateProceduresMap.size(),"blue07" );
    
    ccrViewHiddenBlue(UpdateImmunizationsMap.size(),"blue08" );
    
    ccrViewHiddenBlue(UpdateEncountersMap.size(),"blue09" );
    
    
    
    
    ccrViewHiddenRed(AdvanceDirectivesMap.size(),"red01" );
    ccrViewHiddenRed(AlertsMap.size(),"red02" );
    
    //ccr date
    db.transaction(populateDBupdate, errorCB, successCB);
    undisplayloading();
    
    contentsPaging('contents14');contentsScroll('contentsScroll14');showHiddenTopInstall('none','');
    callRed();
    
    
    
   



}

function populateDBupdate(tx) {
    
    tx.executeSql("update ccr set updatedate = datetime('now')");
    console.log("index.ajax.js >> -------------------- now >>>>>>>>>> ");
    
   
       
}

function lifeManagerList(id,pw){
    
    console.log("index.ajax.js >> -------------------- lifelogList() ");
    
    v01Map           =	 new Map();
    v02Map           =	 new Map();
    v03Map           =	 new Map();
    
    
    console.log("index.ajax.js >>lifelog init");
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_lifemanager_list.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           async: false,
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw} ]}
                               ),
           dataType: "json",
           success: function(data) {
           
           
           $(data.v01).each(function(key,val){
                            console.log("index.ajax.js >>lifelog v01Map " + val);
                            v01Map.put(key,val);
                            });
           $(data.v02).each(function(key,val){
                            console.log("index.ajax.js >>lifelog v02Map " + val);
                            v02Map.put(key,val);
                            });
           $(data.v03).each(function(key,val){
                            console.log("index.ajax.js >>lifelog v03Map " + val);
                            v03Map.put(key,val);
                            });
           
           
           $(data.f01).each(function(key,val){
                            console.log("index.ajax.js >>lifelog f01Map " + val);
                            f01Map.put(key,val);
                            });
           $(data.f02).each(function(key,val){
                            console.log("index.ajax.js >>lifelog f02Map " + val);
                            f02Map.put(key,val);
                            });
           
           $(data.e01).each(function(key,val){
                            console.log("index.ajax.js >>lifelog e01Map " + val);
                            e01Map.put(key,val);
                            });
           $(data.e02).each(function(key,val){
                            console.log("index.ajax.js >>lifelog e02Map " + val);
                            e02Map.put(key,val);
                            });
           
           $(data.b01).each(function(key,val){
                            console.log("index.ajax.js >>lifelog b01Map " + val);
                            b01Map.put(key,val);
                            });
           $(data.b02).each(function(key,val){
                            console.log("index.ajax.js >>lifelog b02Map " + val);
                            b02Map.put(key,val);
                            });
           
           for(y=0; y < v01Map.size(); y++){
           console.log("index.ajax.js >> [[[ kaist-lifemanager ]]] FunctionalStatus insert Description : "+v01Map.get(y));
           var query = "insert into FunctionalStatus (Problem_Desc,Description,Type,Testresult_Value,Testresult_Unit,Datetime_type,Datetime_value) "+
           " values ('諛⑸Ц��μ��/"+v01Map.get(y)+"','','��쇱��������','"+v02Map.get(y)+"' ,'min','Date of Onset','"+v03Map.get(y)+"')";
           insertPropertyx(query,"lifemanager data");
           }
           
           for(y=0; y < f01Map.size(); y++){
           console.log("index.ajax.js >> [[[ kaist-lifemanager ]]] FunctionalStatus insert Description : "+f01Map.get(y));
           var query = "insert into FunctionalStatus (Problem_Desc,Description,Type,Testresult_Value,Testresult_Unit,Datetime_type,Datetime_value) "+
           " values ('���痍⑥�대��','','��쇱��������','"+f01Map.get(y)+"' ,'cal/kcal','Date of Onset','"+f02Map.get(y)+"')";
           insertPropertyx(query,"lifemanager data");
           }
           for(y=0; y < e01Map.size(); y++){
           console.log("index.ajax.js >> [[[ kaist-lifemanager ]]] FunctionalStatus insert Description : "+e01Map.get(y));
           var query = "insert into FunctionalStatus (Problem_Desc,Description,Type,Testresult_Value,Testresult_Unit,Datetime_type,Datetime_value) "+
           " values ('���紐⑥�대��','','��쇱��������','"+e01Map.get(y)+"' ,'cal/kcal','Date of Onset','"+e02Map.get(y)+"')";
           insertPropertyx(query,"lifemanager data");
           }
           
           for(y=0; y < b01Map.size(); y++){
           
           var query =
           " insert into VitalSigns (Phr_Id,Description,Type,Testresult_Value,Testresult_Unit,Datetime_Type,Actor_Id,Actor_Role,Datetime_Value,CCRDataObjectID,Flag) values ( "+
           "1, '"+
           "bmi"                    +"', '"+
           "���泥댁땐��ㅼ�����"                      +"', '"+
           b01Map.get(y)        +"', '"+
           ""                        +"', '"+
           ""                          +"', '"+
           "蹂몄��"                       +"', '"+
           "������"                       +"', '"+
           b02Map.get(y)              + "', '" +
           ""                          +"','1') ";


           insertPropertyx(query,"lifemanager data");
           }
           
           
           },
           error: function(msg) {
           alert(msg.statusText);
           console.log("index.ajax.js >>lifelogList error " +msg.statusText);
           }
           });
}


function loginChk2(id,pw,device_id){
    
    console.log("index.ajax.js >> -------------------- loginChk2() !!! ");
    
    
    displayloading();
    nowAvatarId = id;
    nowAvatarPw = pw;
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_loginchk.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           //timeout:30000,
           //contentType:"application/json; charset=UTF-8",
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw, "device_id" : device_id} ]}
                               ),
           dataType: "json",
           success: function(data) {
           $(data.login).each(function(key,val){
                              console.log("index.ajax.js >> "+val.ack);
                              var ack = val.ack;
                              
                              if(ack == "succ"){
                              window.scrollTo(0,0);
                              sessionStorage.setItem("id",id);
                              
                              //initialCCR();  //���耳�������
                              mainGo();
                              }else{
                              alert("ID OR Password Check Please!");
                              }
                              
                              
                              
                              });
           
           },
           error: function(msg) {
           alert(msg.statusText);
           console.log("index.ajax.js >>loginChk error " +msg.statusText);
           }
           });
    
    /*
     $('#modify').attr('value','true');*/
    contractList(id,pw);
    console.log("index.ajax.js >>-----contractList --------------------------------------------------");
    recommendList(id,pw);
    console.log("index.ajax.js >>-----recommendList --------------------------------------------------");
    settingList(id,pw);
    console.log("index.ajax.js >>-----settingList --------------------------------------------------");
    agentList();
    console.log("index.ajax.js >>-----agentList --------------------------------------------------");
    lifelogList(id,pw);
    console.log("index.ajax.js >>-----lifelogList --------------------------------------------------");
    
    var panelScroll = new iScroll("panelScroll",{hScroll:false});
    // var panelScroll = new IScroll('#panelScroll', { mouseWheel: true });
}

var dataReturn;


function agentList(){
    
    agentListMap            =    new Map();
    agentListIdxMap         =    new Map();
    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_agent_list.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           async: false,
           dataType: "json",
           success: function(data) {
           $(data.agentList).each(function(key,val){
                                  agentListMap.put(key,val);
                                  });
           $(data.agentListIdx).each(function(key,val){
                                     agentListIdxMap.put(key,val);
                                  });
           $("span#notiall").text(""+agentListMap.size());
           },
           error: function(msg) {
           alert(msg.statusText);
           console.log("index.ajax.js >>agentList error " +msg.statusText);
           }
           });
    
    //console.log("index.ajax.js >>////////////////////total count agentListMap : "+agentListMap.size());
    
    for(y=0; y < agentListMap.size(); y++){
        console.log("index.ajax.js >> ## agentListMap : "+agentListMap.get(y) + " " + agentListIdxMap.get(y));
    }
}



function lifelogList(id,pw){
    
    console.log("index.ajax.js >> -------------------- lifelogList() ");
    
     JdateMap           =	 new Map();
     JhourMap           =	 new Map();
     JactiMap           =	 new Map();
     JperiMap           =	 new Map();
    
    console.log("index.ajax.js >>lifelog init");
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_lifelog_list.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           async: false,
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw} ]}
                               ),
           dataType: "json",
           success: function(data) {           
           
           
           $(data.jdate).each(function(key,val){
                              console.log("index.ajax.js >>lifelog jdate " + val);
                              JdateMap.put(key,val);
                                  });
           $(data.jhour).each(function(key,val){
                              console.log("index.ajax.js >>lifelog jhour " + val);
                              JhourMap.put(key,val);
                                     });
           $(data.jacti).each(function(key,val){
                              console.log("index.ajax.js >>lifelog jacti " + val);
                              JactiMap.put(key,val);
                              });
           $(data.jperi).each(function(key,val){
                              console.log("index.ajax.js >>lifelog jperi " + val);
                              JperiMap.put(key,val);
                              });
           
           for(y=0; y < JdateMap.size(); y++){
                    console.log("index.ajax.js >> [[[ kaist-lifelog ]]] Agent_FunctionalStatus insert Description : "+JactiMap.get(y));
                    var query = "insert into Agent_FunctionalStatus (Description,Type,Testresult_Value,Testresult_Unit,Datetime_type,Datetime_value) "+
                        " values ('"+JactiMap.get(y)+"','Activities of Dailiy Living ','"+JperiMap.get(y)+"/"+JhourMap.get(y)+"' ,'m/s','Date of Onset','"+JdateMap.get(y)+"')";
                    insertPropertyx(query,"lifelog data");
           }
           
         
           
          
           },
           error: function(msg) {
                alert(msg.statusText);
                console.log("index.ajax.js >>lifelogList error " +msg.statusText);
           }
           });
}


var cur_id,cur_idx,cur_name;

function agentDoIt(idx,id,bool){        
    
    console.log("index.ajax.js >> -------------------- agentDoIt() ");
    
    var chk = "F";
    
    if(bool == 1){
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_agent_details.jsp",
           data: "idx="+idx+"&id="+id,
           cache:false,
           async: false,
           
           success: function(data) {
           cur_idx = idx;
           cur_id = id;
           dataReturn = data.split(":!");
           cur_name=dataReturn[1];
           /*
           $("#agentName").text("Name:"+dataReturn[1]);
           $("#agentLoaction").text("Location:"+dataReturn[2]);
           //$("#agentRequirement").text("Requirement:"+dataReturn[3]);
           //$("#agentPersonal").text("Personal:"+dataReturn[4]);
           $("#agreeimgN").attr("src","http://healthavatar.snubi.org:8080/Developer/img/"+agentListIdxMap.get(idx-1)+".png");
           
           $("#agentCategory").text("Category:"+dataReturn[4]);
           $("#agentDescription").text("Description:"+dataReturn[5]);
            */
           
           
           $("#agentName").text(""+dataReturn[1]);
           $("#agentLoaction").text(""+dataReturn[2]);
           $("#agreeimgN").attr("src","http://healthavatar.snubi.org:8080/Developer/img/"+idx+".png");
           $("#agentCategory").text("Category:"+dataReturn[4]);
           $("#agentDescription").text("Description:"+dataReturn[5]);
           
           for(var i =0;i < contractListIdxMap.size(); i++ ){
            if( idx ==   contractListIdxMap.get(i) ){
                chk = "T";
            }
                console.log("index.ajax.js >> "+ i + " contractListIdxMap " + contractListIdxMap.get(i) + "  idx = " + idx);
           }
           
                      
           
           $( "#agreeMenu" ).popup( "open" );
           if(chk == "F"){
           console.log("index.ajax.js >>F install");
           //$('#Uninstall').attr("style","display:none");
           //$('#install').attr("style","display:block");
           document.getElementById("install").style.display = "block";
           document.getElementById("uninstall").style.display = "none";
           
           }else{
           console.log("index.ajax.js >>T Uninstall");
           //$('#install').attr("style","display:none");
           //$('#Uninstall').attr("style","display:block");
           document.getElementById("install").style.display = "none";
           document.getElementById("uninstall").style.display = "block";
           
           }

           
           
           },
           error: function(msg) {
           alert(msg.statusText);
            console.log("index.ajax.js >>agentDoIt error " +msg.statusText);
           }
           });
    }
    
    
}


function agentDoItRecomm(idx,id,bool){
    
    
     console.log("index.ajax.js >> -------------------- agentDoItRecomm() ");
    
    $( "#mainPanel" ).panel( "close" );
    contentsPaging('contents4');
    recommendListView('contentsScroll4');
    showHiddenTopInstall('none','');
    
    
    
    var chk = "F";
    
    if(bool == 1){
        $.ajax({
               type: "POST",
               url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_agent_details.jsp",
               data: "idx="+idx+"&id="+id,
               cache:false,
               async: false,
               
               success: function(data) {
               cur_idx = idx;
               cur_id = id;
               dataReturn = data.split(":!");
               cur_name=dataReturn[1];
               /*
                $("#agentName").text("Name:"+dataReturn[1]);
                $("#agentLoaction").text("Location:"+dataReturn[2]);
                //$("#agentRequirement").text("Requirement:"+dataReturn[3]);
                //$("#agentPersonal").text("Personal:"+dataReturn[4]);
                $("#agreeimgN").attr("src","http://healthavatar.snubi.org:8080/Developer/img/"+agentListIdxMap.get(idx-1)+".png");
                
                $("#agentCategory").text("Category:"+dataReturn[4]);
                $("#agentDescription").text("Description:"+dataReturn[5]);
                */
               
               
               $("#agentName").text(""+dataReturn[1]);
               $("#agentLoaction").text(""+dataReturn[2]);
               $("#agreeimgN").attr("src","http://healthavatar.snubi.org:8080/Developer/img/"+idx+".png");
               $("#agentCategory").text("Category:"+dataReturn[4]);
               $("#agentDescription").text("Description:"+dataReturn[5]);
               
               for(var i =0;i < contractListIdxMap.size(); i++ ){
               if( idx ==   contractListIdxMap.get(i) ){
               chk = "T";
               }
               console.log("index.ajax.js >> "+ i + " contractListIdxMap " + contractListIdxMap.get(i) + "  idx = " + idx);
               }
               
               
               
               $( "#agreeMenu" ).popup( "open" );
               if(chk == "F"){
               console.log("index.ajax.js >>F install");
               //$('#Uninstall').attr("style","display:none");
               //$('#install').attr("style","display:block");
               document.getElementById("install").style.display = "block";
               document.getElementById("uninstall").style.display = "none";
               
               }else{
               console.log("index.ajax.js >>T Uninstall");
               //$('#install').attr("style","display:none");
               //$('#Uninstall').attr("style","display:block");
               document.getElementById("install").style.display = "none";
               document.getElementById("uninstall").style.display = "block";
               
               }
               
               
               
               },
               error: function(msg) {
               alert(msg.statusText);
               console.log("index.ajax.js >>agentDoIt error " +msg.statusText);
               }
               });
    }
    
    
}


function agentAgree(){
    
    console.log("index.ajax.js >> -------------------- agentAgree() ");
    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_contract.jsp",
           data: "idx="+cur_idx+"&location="+dataReturn[2]+"&id="+cur_id,
           cache:false,
           async: false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           success: function(data) {
            $( "#agreeMenu" ).popup( "close" );
           console.log("index.ajax.js >>agreed");
           /*
           if(data=="agree")
           toastr.success(cur_name,"Contract Ok");
           else
                      toastr.error(cur_name,"Already contracted");
            */
           
            $( "#mainPanel" ).panel( "open" );
           
           loginAction();
          
           },
           error: function(msg) {
           $( "#agreeMenu" ).popup( "close" );
           console.log("index.ajax.js >>denied");

           }
           });
    
    
}

function agentUninstallPop(){
    
    console.log("index.ajax.js >> -------------------- agentUninstallPop() ");
    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_contract_uninstall.jsp",
           data: "idx="+cur_idx+"&id="+cur_id,
           cache:false,
           async: false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           success: function(data) {
           $( "#agreeMenu" ).popup( "close" );
           console.log("index.ajax.js >>agreed");
           /*
            if(data=="agree")
            toastr.success(cur_name,"Contract Ok");
            else
            toastr.error(cur_name,"Already contracted");
            */
           
           $( "#mainPanel" ).panel( "open" );
           
           
           loginAction();
           
           },
           error: function(msg) {
           $( "#agreeMenu" ).popup( "close" );
           console.log("index.ajax.js >>denied");
           
           }
           });
    
    
}


function agentUninstall(idx,id){
    
     console.log("index.ajax.js >> -------------------- agentUninstall() ");
    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_contract_uninstall.jsp",
           data: "idx="+idx+"&id="+id,
           cache:false,
           async: false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           success: function(data) {
           //$( "#agreeMenu" ).popup( "close" );
           console.log("index.ajax.js >>agreed");
           /*
            if(data=="agree")
            toastr.success(cur_name,"Contract Ok");
            else
            toastr.error(cur_name,"Already contracted");
            */
           loginAction();
           $( "#mainPanel" ).panel( "open" );
           
           
                     },
           error: function(msg) {
           //$( "#agreeMenu" ).popup( "close" );
           console.log("index.ajax.js >>denied");
           
           }
           });    
    
}


function contractList(id,pw){
    
    
     console.log("index.ajax.js >> -------------------- contractList() ");
    
     contractListMap = new Map();
    contractListIdxMap         =    new Map();
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_contracted_list.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           //timeout:30000,
           async: false,
           dataType: "json",
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw} ]}
                               ),
           success: function(data) {
           $(data.agentList).each(function(key,val){
                                  contractListMap.put(key,val);
                                  });
           $(data.agentListIdx).each(function(key,val){
                                  contractListIdxMap.put(key,val);
                                  contractListIdxMapAlertNo.put(val,0);
                                  //console.log("index.ajax.js >>############## key : "+key);
                                  //console.log("index.ajax.js >>############## val : "+val);

                                  });
            for(y=0; y < contractListMap.size(); y++){
                console.log("index.ajax.js >> ## contractListMap : "+contractListMap.get(y));
            }
           },
           error: function(msg) {
           alert(msg.statusText);
           }
           });
    //console.log("index.ajax.js >>contractUi ------------");
    //contractUi();
    testUI();
    //console.log("index.ajax.js >>contractUi ------------");
}

function recommendList(id,pw){
    
    console.log("index.ajax.js >> -------------------- recommendList() ");
    
    recommendListMap = new Map();
    recommendListIdxMap = new Map();
    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_recommend_list.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           //timeout:30000,
           async: false,
           dataType: "json",
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw} ]}
                               ),
           success: function(data) {
           $(data.agentList).each(function(key,val){
                                  recommendListMap.put(key,val);
                                  });
           $(data.agentListIdx).each(function(key,val){
                                  recommendListIdxMap.put(key,val);
                                  });
           for(y=0; y < recommendListMap.size(); y++){
               console.log("index.ajax.js >> ## recommendListMap : "+recommendListMap.get(y));
           }           
           
           },
           error: function(msg) {
           alert(msg.statusText);
           }
           });
    
    recommendUi();
    
}

function settingList(id,pw){
    
    console.log("index.ajax.js >> -------------------- settingList() ");
    
    settingListMap = new Map();
    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_setting_avatar.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           //timeout:30000,
           async: false,
           dataType: "json",
           data:JSON.stringify(
                               {"loginchk" : [ {"id" : id, "pw" : pw} ]}
                               ),
           success: function(data) {
           $(data.setting).each(function(key,val){
                                                                  
                                settingListMap.put("id",val.id);
                                settingListMap.put("modify",val.modify);
                                settingListMap.put("email",val.email);
                                settingListMap.put("birth_date",val.birth_date);
                                settingListMap.put("sex",val.sex);
                                settingListMap.put("smoker",val.smoker);
                                settingListMap.put("drinking",val.drinking);
                                settingListMap.put("height",val.height);
                                settingListMap.put("weight",val.weight);
                                settingListMap.put("Preventivecare",val.Preventivecare);
                                settingListMap.put("Medicationalert",val.Medicationalert);
                                settingListMap.put("Healthmonitoring",val.Healthmonitoring);
                                settingListMap.put("Diagnosis",val.Diagnosis);
                                settingListMap.put("Entertainment",val.Entertainment);
                                settingListMap.put("DiseaseControl",val.DiseaseControl);
                                settingListMap.put("HealthQA",val.HealthQA);
                                settingListMap.put("MedicalResearch",val.MedicalResearch);
                                
                                  });           
                           
                var height = settingListMap.get("height");
                var weight = settingListMap.get("weight");
                var bmi = ((weight/(height/100))/(height/100)).toFixed(2);
           
                var mf = "";
           
                $("#idt").attr("value",settingListMap.get("id"));
                $("#modify").attr("value",settingListMap.get("modify"));
                $("#email").attr("value",settingListMap.get("email"));
                $("#birth_date").attr("value",settingListMap.get("birth_date"));
                $("#height").attr("value",settingListMap.get("height"));
                $("#weight").attr("value",settingListMap.get("weight"));
                $("#bmi").attr("value",bmi);           
                $("#profileID").text("ID : "+settingListMap.get("id"));
                $("#profileHEIGHT").text("HEIGHT : "+settingListMap.get("height"));
                $("#profileWEIGHT").text("WEIGHT : "+settingListMap.get("weight"));
                $("#profileBMI").text("BMI : "+bmi);
           
                if(settingListMap.get("sex") == "1"){
                    $("#sexa").attr("checked",true).checkboxradio("refresh");
                    $("#profileSEX").text("SEX : MALE");
                    mf = "<img src='img/male.png' valign='middle'>";
                }
                else{
                    $("#sexb").attr("checked",true).checkboxradio("refresh");
                    $("#profileSEX").text("SEX : FEMALE");
                    mf = "<img src='img/female.png' valign='middle'>";
                }
                if(settingListMap.get("smoker") == "1")
                    $("#smokera").attr("checked",true).checkboxradio("refresh");
                else
                    $("#smokerb").attr("checked",true).checkboxradio("refresh");
           
                if(settingListMap.get("drinking") == "1")
                    $("#drinkinga").attr("checked",true).checkboxradio("refresh");
                else
                    $("#drinkingb").attr("checked",true).checkboxradio("refresh");
           
           
                if(settingListMap.get("Preventivecare") == "checked")
                    $("#Preventivecare").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("Medicationalert") == "checked")
                    $("#Medicationalert").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("Healthmonitoring") == "checked")
                    $("#Healthmonitoring").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("Diagnosis") == "checked")
                    $("#Diagnosis").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("Entertainment") == "checked")
                    $("#Entertainment").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("DiseaseControl") == "checked")
                    $("#DiseaseControl").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("HealthQA") == "checked")
                    $("#HealthQA").attr("checked",true).checkboxradio("refresh");
                if(settingListMap.get("MedicalResearch") == "checked")
                    $("#MedicalResearch").attr("checked",true).checkboxradio("refresh");
           
           
           var topid =   mf + " &nbsp;&nbsp;&nbsp;   " + settingListMap.get("id") + " (" + ck_age(settingListMap.get("birth_date").substr(0,4)) + "세)" ;
           $("#topid").html(topid);
           
           
           },
           error: function(msg) {
           alert(msg.statusText);
           }
           });    
}


function ck_age(str) {
    var year=parseInt(new Date().getFullYear());
    
    var ck=parseInt(str);
    
    return (year-ck)+1; // ��곕━������ ������ ������ +1 ������
}


function sendSettingList(){
    
    console.log("index.ajax.js >> -------------------- sendSettingList() ");
    
    var preferenceAll = "";
    
    if($("#password").val() == ""){
        alert("鍮�諛�踰���몃�� �����ν����몄��!");
        document.getElementById("password").focus();
        return false;
    }
    
    if($("#password").val() != nowAvatarPw){
        alert("鍮�諛�踰���몃�� �����명����몄��!");
        document.getElementById("password").focus();
        return false;
    }
    
    
    var datas  = "id="+$("#idt").val()+"&";
    datas  += "password="+$("#password").val()+"&";
    datas  += "modify="+$("#modify").val()+"&";
    datas  += "email="+$("#email").val()+"&";
    datas  += "birth_date="+$("#birth_date").val()+"&";
    datas  += "height="+$("#height").val()+"&";
    datas  += "weight="+$("#weight").val()+"&";
    datas  += "BMI="+$("#bmi").val()+"&";
        
    $("input[name*=sex]:checked").each(function () {
            datas  += "sex="+$(this).val()+"&";                                       
     });
    $("input[name*=smoker]:checked").each(function () {
            datas  += "smoker="+$(this).val()+"&";
    });
    $("input[name*=drinking]:checked").each(function () {
            datas  += "drinking="+$(this).val()+"&";
    });
    $("input[name*=Preventivecare]:checked").each(function () {
           preferenceAll += $(this).val() + "\t";
     });
    $("input[name*=Medicationalert]:checked").each(function () {
           preferenceAll += $(this).val() + "\t";
    });
    $("input[name*=Healthmonitoring]:checked").each(function () {
            preferenceAll += $(this).val() + "\t";
    });
    $("input[name*=Diagnosis]:checked").each(function () {
            preferenceAll += $(this).val() + "\t";
    });
    $("input[name*=Entertainment]:checked").each(function () {
            preferenceAll += $(this).val() + "\t";
    });
    $("input[name*=DiseaseControl]:checked").each(function () {
            preferenceAll += $(this).val() + "\t";
    });
    $("input[name*=HealthQA]:checked").each(function () {
            preferenceAll += $(this).val() + "\t";
    });
    $("input[name*=MedicalResearch]:checked").each(function () {
            preferenceAll += $(this).val() + "\t";
    });
    
    datas  += "preferenceAll="+preferenceAll+"&";
    
    console.log("index.ajax.js >>preferenceAll" + preferenceAll);
    console.log("index.ajax.js >>datas" + datas);

    
    $.ajax({
           type: "POST",
           url:  sessionStorage.getItem("ROOTDOMAIN") + "aatest_regist_avatar.jsp",
           cache:false,
           headers: { "cache-control": "no-cache","pragma": "no-cache" },
           //timeout:30000,
           async: false,
           data:datas,
           success: function(data) {                                
                                
             $( "#popupProfile" ).popup( "close" );
             loginAction();
             $( "#mainPanel" ).panel( "open" );
           
           },
           error: function(msg) {
           alert(msg.statusText);
           }
           });    
}











